package com.sky.mapper;

import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface AdminOrderMapper {

    List<Orders> selectOrdersPage(OrdersPageQueryDTO ordersPageQueryDTO);

    @Select("select COUNT(*) from orders group by status having status = #{status}")
    Integer selectByStatus(Integer status);

    @Select("select * from orders where id = #{id}")
    Orders selectById(Long id);

    @Update("update orders set status = #{status} where pay_status = #{PayStatus} and order_time <= #{orderTime} and status = #{noPay}")
    Integer updateStatusByPayStatusAndOrderTime(Integer status, Integer PayStatus, Integer noPay , LocalDateTime orderTime);

    @Update("update orders set status = #{completed} where status = #{deliveryInProgress}")
    Integer updateStatusByStatus(Integer completed, Integer deliveryInProgress);
}
